<template>
  <system-index @to-main-page="toMainPage">
    <goods-detail ref="sysComp" :has-back="hasBack" @to-page="toPage"></goods-detail>
  </system-index>
</template>

<script>
  import SystemIndex from 'views/systemIndex';
  import GoodsDetail from 'views/goodsDetail';

  import mpMixins from '../mpMixins';

  export default {
    mixins: [mpMixins],

    data() {
      let pages = getCurrentPages();
      return {
        hasBack: pages.length > 1
      };
    },

    created(){
      window.pageName = 'goodsDetail';
      window.addEventListener('wxshow', () => {
        let actionData = window.actionData;
        if (actionData === undefined) {
          return;
        }
        delete window.actionData;

        let type = actionData.type;
        if (type === 'toPage') {
          this.$refs['sysComp'].toShopCartPage(actionData.data);
        }
      });
    },

    components: {
      SystemIndex,
      GoodsDetail
    }
  };

</script>
